public class Order {
    private OrderItem item;
    private OrderItem[] items;
    private int orderId;
    private double total;

    public Order(String s) {
        items = new OrderItem[3]; // 初始化为包含3个订单项的数组
    }

    public void setItem(OrderItem item, int i) {
        if (i >= 0 && i < items.length) {
            items[i] = item;
            orderId = i;
        }
    }

    public OrderItem[] getItems() {
        return items;
    }

    public int getOrderId() {
        return orderId;
    }

    public double getTotal() {
        total = 0.0; // 初始化总额为0
        for (int i = 0; i < items.length; i++) {
            if (items[i] != null) { // 检查订单项是否存在
                total += items[i].getBook().getPrice() * items[i].getNum();
            }
        }
        return total;
    }
}
